Computer Science Lesson Plan
Class: 7 - Lesson: 10 Functions (Predefined and User Defined)

Purpose: To learn about predefined and user-defined functions, and to use functions in programming (My Blocks).

No. of Classes

One or two classes (teacher's decision).

Material Required

Computer, Scratch 3.0, internet connection (Code.org).

Curriculum Content
  • 2.7) Functions
  • 2.9) Blocks
  • Prior Knowledge

    Students should know:

  • How to use variables, operators, loops and conditional statements.
  • How to create and use a list.
  • Exercises

    Exercise 1



    1. Create a Scratch program to make a sprite walk. After the exercise, explain that this program uses the predefined (built-in) functions in Scratch.

    Exercise 2



    1. There are several pumpkins in each patch. Look carefully at the function definitions below to work out how to use each one.

    No Image

    Exercise 3



    1. Write an improved program to find the prime numbers from 2 to N. Get the value of N from the user, and store the prime numbers in a list as you find them. Use a user-defined block to check whether a number is prime and to insert it into the list.

    Solutions



  • Link to copy the solution program for Exercise 1.
  • Link to view the solution image for Exercise 2.
  • Link to copy the solution program for Exercise 3.

  • Teacher Instructions
    1. Teachers should first explain what a function is - a named group of instructions that can be reused whenever it is needed, instead of writing the same blocks again and again.
    2. Teachers should then explain the difference between predefined functions (the blocks Scratch already provides) and user-defined functions (the blocks students create themselves under My Blocks).
    3. Teachers should devise their own creative activity to help students understand predefined functions, using the built-in blocks in Scratch.
    4. Teachers can use the model videos to learn about predefined and user-defined functions.
    5. POINTS TO PONDER: Do you know about modules?